//
//  DetailsViewController.m
//  A_Comic
//
//  Created by sos on 16/1/18.
//  Copyright © 2016年 sos. All rights reserved.
//

#import "DetailsViewController.h"
#import "HomePageModel.h"
#import <AFNetworking.h>
#import <UIImageView+WebCache.h>
#import <FXBlurView.h>
#import "CatalogueCollectionCell.h"
#import "ReviewTableViewCell.h"
#import "ReadViewController.h"
#import "DownLoadViewController.h"
@interface DetailsViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate,houDelegate>
@property (nonatomic,retain) UIScrollView *scrollView;//整个页面是一个scrollView
@property (nonatomic,retain) HomePageModel *hp;//接受本地储存的数据
@property (nonatomic,retain) NSMutableArray *dataArrOne;//目录数据数组
@property (nonatomic,retain) NSMutableArray *dataArrTwo;//评论数据数组
@property (nonatomic,retain) NSMutableArray *dataArrThree;//正序
@property (nonatomic,retain) UIScrollView *hengScrollView;//横向滑动
@property (nonatomic,retain) UICollectionView *collection;//目录列表
@property (nonatomic,retain) UITableView *tabelView;//评论列表
//@property (nonatomic,assign) BOOL isT;//布尔值表示状态 来确认是否弹出控制器
@property (nonatomic,retain) NSString *mm;//记录当前漫画的总话数
@property (nonatomic,assign) BOOL isM;
//@property (nonatomic,retain) ReadViewController *readVC;
@end

@implementation DetailsViewController
//    static ReadViewController *readVC;
-(void)dealloc{
//    [_readVC release];
    
    
    [super dealloc];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _isM = NO;
    self.view.backgroundColor = [UIColor whiteColor];
//    _isT = YES;
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
//    static ReadViewController *readVC;
    // Do any additional setup after loading the view.
    
    [self data];
   
    

    
}

-(void)data
{
    //详情的数据
    NSString *url = [NSString stringWithFormat:@"http://mobilev3.ac.qq.com/Comic/comicDetailForIosV2/uin/0/local_version/3.5.1/channel/1001/guest_id/FBB11919-34E9-4168-9491-811B4C0BDBD6/comic_id/%@",self.m.comic_id];

    self.dataArrOne = [NSMutableArray array];
    self.dataArrTwo = [NSMutableArray array];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dic = responseObject[@"data"][@"comic"] ;
        HomePageModel *m = [[HomePageModel alloc]init];
        [m setValuesForKeysWithDictionary:dic];
        self.hp = m;
        
//
        //整个页面
        self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
//        self.scrollView.backgroundColor = [UIColor yellowColor];
        self.scrollView.contentSize = CGSizeMake(0, 800);
//        self.scrollView0.pagingEnabled = YES;

        [self.view addSubview:self.scrollView];
        
        [self.scrollView release];
        
        //背景
        UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(0,-20, self.view.frame.size.width, 200)];
//        view.backgroundColor = [UIColor blueColor];
        [view sd_setImageWithURL:[NSURL URLWithString:m.cover_url]];
        //玻璃话
        FXBlurView *fx = [[FXBlurView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
        //图片的用户交互
        view.userInteractionEnabled = YES;
        
        [view addSubview:fx];
        [self.scrollView addSubview:view];
        [fx release];
        [view release];
        
        // 返回按钮
        UIButton *blackButton = [UIButton buttonWithType:UIButtonTypeCustom];
        blackButton.frame = CGRectMake(0, 25, self.view.frame.size.width/10, view.frame.size.height/5);
//        blackButton.backgroundColor = [UIColor brownColor];
        [blackButton setTitle:@"返回" forState:UIControlStateNormal];
        [blackButton addTarget:self action:@selector(black:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:blackButton];
        
        //图片
        UIImageView *pickImg = [[UIImageView alloc]initWithFrame:CGRectMake(blackButton.frame.size.width, blackButton.frame.origin.y+blackButton.frame.size.height, self.view.frame.size.width/3, view.frame.size.height-blackButton.frame.origin.y-blackButton.frame.size.height)];
        [pickImg sd_setImageWithURL:[NSURL URLWithString:m.cover_url]];
//        pickImg.backgroundColor = [UIColor purpleColor];
        [view addSubview:pickImg];
        [pickImg release];
        
        //收藏按钮
        UIButton *joinButton = [UIButton buttonWithType:UIButtonTypeCustom];
        joinButton.frame = CGRectMake(self.view.frame.size.width/4*3, blackButton.frame.origin.y, blackButton.frame.size.width, blackButton.frame.size.height);
//        joinButton.backgroundColor = [UIColor redColor];
        [joinButton setTitle:@"收藏" forState:UIControlStateNormal];
        [joinButton addTarget:self action:@selector(shoucang:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:joinButton];
        
        //  分享按钮
        UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        shareButton.frame = CGRectMake(joinButton.frame.origin.x+joinButton.frame.size.width+10, joinButton.frame.origin.y, joinButton.frame.size.width, joinButton.frame.size.height);
//        shareButton.backgroundColor = [UIColor greenColor];
        [shareButton setTitle:@"分享" forState:UIControlStateNormal];
        [shareButton addTarget:self action:@selector(fenxiang:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:shareButton];
        
        // 类型标签
        UILabel *typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(pickImg.frame.origin.x + pickImg.frame.size.width+10, pickImg.frame.origin.y+10, self.view.frame.size.width/3, 15)];
        typeLabel.text = m.type;
//        typeLabel.backgroundColor = [UIColor yellowColor];
        [view addSubview:typeLabel];
        [typeLabel release];
        
        
        //名字标签
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(typeLabel.frame.origin.x, typeLabel.frame.origin.y+typeLabel.frame.size.height+5, typeLabel.frame.size.width, 20)];
        titleLabel.text = m.title;
        titleLabel.tag = 6666;
//        titleLabel.backgroundColor = [UIColor grayColor];
        [view addSubview:titleLabel];
        [titleLabel release];
        
        //作者标签
        UILabel *authorLabel = [[UILabel alloc]initWithFrame:CGRectMake(titleLabel.frame.origin.x, titleLabel.frame.origin.y + titleLabel.frame.size.height+5, titleLabel.frame.size.width, 15)];
//        authorLabel.backgroundColor = [UIColor groupTableViewBackgroundColor];
        authorLabel.text = m.artist_name;
        [view addSubview:authorLabel];
        [authorLabel release];
        
        //评分星星
        UIView *starView = [[UIView alloc]initWithFrame:CGRectMake(authorLabel.frame.origin.x, authorLabel.frame.origin.y+authorLabel.frame.size.height+5, authorLabel.frame.size.width, 15)];
//        starView.backgroundColor = [UIColor greenColor];
        [view addSubview:starView];
        [starView release];
        
        //下载按钮
        UIButton *downloadButoon = [UIButton buttonWithType:UIButtonTypeCustom];
        downloadButoon.frame = CGRectMake(10, view.frame.size.height, self.view.frame.size.width/2-20, 50);
        downloadButoon.backgroundColor = [UIColor purpleColor];
        [downloadButoon setTitle:@"下载" forState:UIControlStateNormal];
        [downloadButoon addTarget:self action:@selector(xiazai:) forControlEvents:UIControlEventTouchUpInside];
        [self.scrollView addSubview:downloadButoon];
        
        //开始阅读按钮
        UIButton *startReadButton = [UIButton buttonWithType:UIButtonTypeCustom];
        startReadButton.frame = CGRectMake(downloadButoon.frame.origin.x +downloadButoon.frame.size.width+20, downloadButoon.frame.origin.y, downloadButoon.frame.size.width, downloadButoon.frame.size.height);
        startReadButton.backgroundColor = [UIColor blueColor];
        [startReadButton addTarget:self action:@selector(kaishi:) forControlEvents:UIControlEventTouchUpInside];
        [startReadButton setTitle:@"开始阅读" forState:UIControlStateNormal];
        [self.scrollView addSubview:startReadButton];
        
        //分段控制器
       
        UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"详情",@"目录",@"评论"]];
        seg.tag = 10001;
        seg.frame = CGRectMake(downloadButoon.frame.origin.x + 5, downloadButoon.frame.origin.y+downloadButoon.frame.size.height+10, self.view.frame.size.width-40, 30);
        seg.selectedSegmentIndex = 0;
        [seg addTarget:self action:@selector(bianhua:) forControlEvents:UIControlEventValueChanged];
        [self.scrollView addSubview:seg];
        [seg release];
        
        //横向滑动
        self.hengScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, seg.frame.origin.y+seg.frame.size.height+10, self.view.frame.size.width, 450)];
        self.hengScrollView.contentSize = CGSizeMake(self.view.frame.size.width*3, 0);
//        self.hengScrollView.backgroundColor = [UIColor redColor];
        self.hengScrollView.pagingEnabled = YES;
        self.hengScrollView.delegate = self;
        [self.scrollView addSubview:self.hengScrollView];
        [self.hengScrollView release];
        
        //详情View
        UIView *detaiView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.hengScrollView.frame.size.height)];
//        detaiView.backgroundColor = [UIColor blueColor];
        
        [self.hengScrollView addSubview:detaiView];
        [detaiView release];
        
        //头像图片
        UIImageView *qqHeadImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, self.view.frame.size.width/10, self.view.frame.size.width/10)];
//        qqHeadImage.backgroundColor = [UIColor redColor];
        [qqHeadImage sd_setImageWithURL:[NSURL URLWithString:m.artist_qq_head]];
        qqHeadImage.layer.cornerRadius = self.view.frame.size.width/20;
        qqHeadImage.clipsToBounds = YES;
        [detaiView addSubview:qqHeadImage];
        [qqHeadImage release];
        
    //作者定值标签
        UILabel *LabelOne = [[UILabel alloc]initWithFrame:CGRectMake(qqHeadImage.frame.origin.x + qqHeadImage.frame.size.width +5, qqHeadImage.frame.origin.y, qqHeadImage.frame.size.width, qqHeadImage.frame.size.height/2)];
//        LabelOne.backgroundColor = [UIColor purpleColor];
        LabelOne.text = @"作者";
        LabelOne.textColor = [UIColor grayColor];
        [detaiView addSubview:LabelOne];
        [LabelOne release];
        
     // 作者标签
        UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(LabelOne.frame.origin.x, LabelOne.frame.origin.y+LabelOne.frame.size.height, LabelOne.frame.size.width*2, LabelOne.frame.size.height)];
//        nameLabel.backgroundColor = [UIColor redColor];
        nameLabel.text = m.artist_name;
        [detaiView addSubview:nameLabel];
        [nameLabel release];
        
        //分割线
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(qqHeadImage.frame.origin.x, qqHeadImage.frame.origin.y+qqHeadImage.frame.size.height+15, seg.frame.size.width, 1)];
        lineView.backgroundColor = [UIColor grayColor];
        [detaiView addSubview:lineView];
        [lineView release];
        
        //作品介绍标签
        UILabel *LabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(lineView.frame.origin.x, lineView.frame.origin.y+10, self.view.frame.size.width/6, nameLabel.frame.size.height)];
//        LabelTwo.backgroundColor = [UIColor greenColor];
        LabelTwo.text = @"作品介绍";
        LabelTwo.font = [UIFont systemFontOfSize:15];
        LabelTwo.textColor = [UIColor grayColor];
        [detaiView addSubview:LabelTwo];
        [LabelTwo release];
        
        
        //作品介绍文本
        UILabel *workIntroduce = [[UILabel alloc]initWithFrame:CGRectMake(LabelTwo.frame.origin.x, LabelTwo.frame.origin.y+LabelTwo.frame.size.height+5, lineView.frame.size.width, self.view.frame.size.height/4)];
//        workIntroduce.backgroundColor = [UIColor brownColor];
        workIntroduce.text = m.brief_intrd;
        workIntroduce.numberOfLines = 0;
        [workIntroduce sizeToFit];
        [detaiView addSubview:workIntroduce];
        [workIntroduce release];
        
        //分割线
        UIView *lineTwoView = [[UIView alloc]initWithFrame:CGRectMake(workIntroduce.frame.origin.x, workIntroduce.frame.origin.y+workIntroduce.frame.size.height+15, lineView.frame.size.width, lineView.frame.size.height)];
        lineTwoView.backgroundColor = [UIColor grayColor];
        [detaiView addSubview:lineTwoView];
        [lineTwoView release];
        
        //作品类型标签
        UILabel *LabelThree = [[UILabel alloc]initWithFrame:CGRectMake(LabelTwo.frame.origin.x, lineTwoView.frame.origin.y+lineTwoView.frame.size.height+15, LabelTwo.frame.size.width, LabelTwo.frame.size.height)];
//        LabelThree.backgroundColor = [UIColor greenColor];
        LabelThree.text = @"作品类型";
        LabelThree.font = [UIFont systemFontOfSize:15];
        LabelThree.textColor = [UIColor grayColor];
        [detaiView addSubview:LabelThree];
        [LabelThree release];
        
        
        //作品
        UILabel *workTepy = [[UILabel alloc]initWithFrame:CGRectMake(LabelThree.frame.origin.x, LabelThree.frame.origin.y+LabelThree.frame.size.height+10, self.view.frame.size.width/3, 20)];
//        workTepy.backgroundColor = [UIColor purpleColor];
        workTepy.text = m.type;
        [detaiView addSubview:workTepy];
        [workTepy release];
        
        //更新时间
        UILabel *labelFour = [[UILabel alloc]initWithFrame:CGRectMake(LabelThree.frame.origin.x, workTepy.frame.origin.y+workTepy.frame.size.height+15, LabelThree.frame.size.width, LabelThree.frame.size.height)];
//        labelFour.backgroundColor = [UIColor greenColor];
        labelFour.text = @"更新时间";
        labelFour.font = [UIFont systemFontOfSize:15];
        labelFour.textColor = [UIColor grayColor];
        [detaiView addSubview:labelFour];
        [labelFour release];
        
        //更新时间文本
        UILabel *updateTime = [[UILabel alloc]initWithFrame:CGRectMake(workTepy.frame.origin.x, labelFour.frame.origin.y+labelFour.frame.size.height+15,labelFour.frame.size.width+20, workTepy.frame.size.height)];
//        updateTime.backgroundColor = [UIColor brownColor];
        NSString *str = [[m.update_date stringByReplacingOccurrencesOfString:@"-" withString:@"."] substringToIndex:10];
        
        updateTime.text = str;
        
        [detaiView addSubview:updateTime];
        [updateTime release];
        
        //目录滑动
        
        //目录View
        
        UIView *catalogueView = [[UIView alloc]initWithFrame:CGRectMake(detaiView.frame.size.width, 0, detaiView.frame.size.width, self.hengScrollView.frame.size.height)];
        catalogueView.tag = 2000;
//        catalogueView.backgroundColor = [UIColor greenColor];
        [self.hengScrollView addSubview:catalogueView];
        [catalogueView release];
        
        //时间标签
        UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(downloadButoon.frame.origin.x, 10, self.view.frame.size.width/4, 20)];
        timeLabel.tag = 3000;
//        timeLabel.backgroundColor = [UIColor brownColor];
        timeLabel.text = str;
        [catalogueView addSubview:timeLabel];
        [timeLabel release];
        
        //更新标签
        UILabel *updateLabel = [[UILabel alloc]initWithFrame:CGRectMake(timeLabel.frame.origin.x+timeLabel.frame.size.width, timeLabel.frame.origin.y, timeLabel.frame.size.width, timeLabel.frame.size.height)];
//        updateLabel.backgroundColor = [UIColor redColor];
        updateLabel.text = [NSString stringWithFormat:@"更新到%@",m.lastup];
        [updateLabel sizeToFit];
        self.mm = m.lastup;
        [catalogueView addSubview:updateLabel];
        [updateLabel release];
        
        //按钮正序／反序
        UIButton *orderButton = [UIButton buttonWithType:UIButtonTypeCustom];
        orderButton.frame = CGRectMake(self.view.frame.size.width/10*9, updateLabel.frame.origin.y, self.view.frame.size.width/10, updateLabel.frame.size.height);
//        orderButton.backgroundColor = [UIColor yellowColor];
        [orderButton setTitle:@"正序" forState:UIControlStateNormal];
        [orderButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [orderButton addTarget:self action:@selector(order:) forControlEvents:UIControlEventTouchUpInside];
        [catalogueView addSubview:orderButton];
        
        
//        //目录collectionView
//        
//        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        
        layout.minimumInteritemSpacing = 10;
        layout.minimumLineSpacing = 20;
        layout.sectionInset = UIEdgeInsetsMake(10, 20, 10, 20);
        layout.itemSize = CGSizeMake((self.view.frame.size.width - timeLabel.frame.origin.x*2-80)/3, 30);
        
        
        
        self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(timeLabel.frame.origin.x, timeLabel.frame.origin.y+timeLabel.frame.size.height+5, self.view.frame.size.width - timeLabel.frame.origin.x*2, catalogueView.frame.size.height-timeLabel.frame.origin.y-timeLabel.frame.size.height) collectionViewLayout:layout];
        
        
        self.collection.delegate = self;
        self.collection.dataSource = self;
        
        self.collection.backgroundColor = [UIColor whiteColor];
        [self.collection registerClass:[CatalogueCollectionCell class] forCellWithReuseIdentifier:@"cell"];
        
        [catalogueView addSubview:self.collection];
        [layout release];
        [self.collection release];
        
        //评论View
        UIView *reviewView = [[UIView alloc]initWithFrame:CGRectMake(detaiView.frame.size.width*2, 0, self.view.frame.size.width, self.hengScrollView.frame.size.height)];
//        reviewView.backgroundColor = [UIColor orangeColor];
        [self.hengScrollView addSubview:reviewView];
        [reviewView release];
        
        
        
        
        
        
        //评论tabelView
        
        self.tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, reviewView.frame.size.width, reviewView.frame.size.height) style:UITableViewStylePlain];
//        self.tabelView.backgroundColor = [UIColor redColor];
        self.tabelView.delegate = self;
        self.tabelView.dataSource = self;
        
        [self.tabelView registerClass:[ReviewTableViewCell class] forCellReuseIdentifier:@"cell0"];
        [reviewView addSubview:self.tabelView];
        [self.tabelView release];
        
        
        
        
        
        
        
        
        

        
        
        
        
        [m release];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
    
    
    //目录数据解析
    NSString *str = [NSString stringWithFormat:@"http://mobilev3.ac.qq.com/Comic/comicChapterListForIosV2/uin/0/local_version/3.5.1/channel/1001/guest_id/FBB11919-34E9-4168-9491-811B4C0BDBD6/comic_id/%@",self.m.comic_id];
    [manager GET:str parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSArray *arr = responseObject[@"data"];

        self.dataArrOne = [HomePageModel modelHandlerWithArray:arr];
        [self.collection reloadData];
        
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
    
    
    
    //评论数据
    NSString *url0 = [NSString stringWithFormat:@"http://mobilev3.ac.qq.com/Comment/commentListForIosV2/comic_id/%@/page/1/listcnt/15/uin/0/local_version/3.5.1/channel/1001/guest_id/FBB11919-34E9-4168-9491-811B4C0BDBD6",self.m.comic_id];
    [manager GET:url0 parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSArray *arr = responseObject[@"data"];

        self.dataArrTwo = [HomePageModel modelHandlerWithArray:arr];
        [self.tabelView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
    
    
}
//collection 协议方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArrOne.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    CatalogueCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor grayColor];

    
//    if (_isT) {
    
        HomePageModel *m = self.dataArrOne[indexPath.item];
        cell.catalogueLabel.text = m.btn_str;
//    }else{
//        HomePageModel *m = self.dataArr3[indexPath.item];
//        cell.catalogueLabel.text = m.btn_str;

//    }
    
    
    return cell;
    
}
//评论tabelView 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArrTwo.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ReviewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell0" forIndexPath:indexPath];
    
    HomePageModel *m = self.dataArrTwo[indexPath.row];
    
    [cell.qqImage sd_setImageWithURL:[NSURL URLWithString:m.qqhead]];
    cell.labelOne.text = m.nickName;
    cell.labelTwo.text = m.date;
    if (m.good_count == nil) {
        cell.labelFour.text = [NSString stringWithFormat:@"0"];
    }else{
        
        cell.labelFour.text = m.good_count;
    }
    cell.labelThree.text = m.reply_count.stringValue;
    
    cell.labelFir.text = m.content;
    
    return cell;
    
    
}
//cell高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomePageModel *m = self.dataArrTwo[indexPath.row];
    CGFloat h = [ReviewTableViewCell heightWihtText:m.content FontOfSize:16];
    
    return 70+h;
}
//返回按钮方法
-(void)black:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//目录collectionView点击
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    ReadViewController *readVC = [[ReadViewController alloc]init];
    HomePageModel *m = self.dataArrOne[indexPath.item];
    m.comic_id = self.m.comic_id;
    readVC.number = self.mm.integerValue;
    readVC.str = m;
    readVC.delegater = self;
    
    
    [self.navigationController pushViewController:readVC animated:NO];
    
}


//分段控制器的方法
-(void)bianhua:(UISegmentedControl *)seg
{

    if (seg.selectedSegmentIndex == 0) {
        [self.hengScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    }else if (seg.selectedSegmentIndex == 1){
        [self.hengScrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0) animated:YES];
    }else if (seg.selectedSegmentIndex == 2){
        [self.hengScrollView setContentOffset:CGPointMake(self.view.frame.size.width*2, 0) animated:YES];
    }
    
    
    
}


//横向滑动的时候 分段控制器跟随变化
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    UISegmentedControl *seg = [self.view viewWithTag:10001];
    if (scrollView == self.hengScrollView) {
        if (self.hengScrollView.contentOffset.x == 0) {
            seg.selectedSegmentIndex = 0;
        }else if (self.hengScrollView.contentOffset.x == 375){
            seg.selectedSegmentIndex = 1;
        }else if (self.hengScrollView.contentOffset.x == 375*2){
            seg.selectedSegmentIndex = 2;
        }
    }
    
    
}
//正反序列方法
-(void)order:(UIButton *)btn
{

    _isM = !_isM;
    
    if (_isM) {
        [btn setTitle:@"反序" forState:UIControlStateNormal];

        for (NSInteger i = 0; i < self.dataArrOne.count/2; i++) {
            

            [self.dataArrOne exchangeObjectAtIndex:i withObjectAtIndex:self.dataArrOne.count-1-i];
            
        }
        [self.collection reloadData];
    }else{
        
        [btn setTitle:@"正序" forState:UIControlStateNormal];

        for (NSInteger i = 0; i < self.dataArrOne.count/2; i++) {
            
            
            [self.dataArrOne exchangeObjectAtIndex:i withObjectAtIndex:self.dataArrOne.count-1-i];
            
        }

        [self.collection reloadData];
    }
    

    
    //枚举器
//    NSEnumerator *enumerator = [self.dataArrOne reverseObjectEnumerator];//倒序
//    [self.dataArrOne removeAllObjects];
//    for (id object = nil; object = [enumerator nextObject];) {
//        [self.dataArrOne addObject:object];
////        NSLog(@"%@",object);
//    }
//    [self.collection reloadData];
    
}
-(void)houDian:(NSInteger)number{
    
    if (_isM == NO) {
        
        [self collectionView:self.collection didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:number+1 inSection:0]];
    }else{
        
       [self collectionView:self.collection didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:self.mm.integerValue - number-2 inSection:0]];
        
    }
}


-(void)houDianTwo:(NSInteger)numberTwo
{
    if (_isM == NO) {
        
        [self collectionView:self.collection didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:numberTwo-1 inSection:0]];
    }else{
        
        [self collectionView:self.collection didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:self.mm.integerValue - numberTwo inSection:0]];
    }
}

//收藏方法
-(void)shoucang:(UIButton *)btn
{
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:@"shoucang.plist"];
//    NSLog(@"%@",NSHomeDirectory());
//    NSLog(@"~~~~~~110");

    NSMutableArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

    if (arr) {
        for (HomePageModel *m in arr) {
            if ([m.title isEqualToString:self.hp.title]) {
                UIAlertController *aler = [UIAlertController alertControllerWithTitle:@"提示" message:@"已存在收藏" preferredStyle:UIAlertControllerStyleAlert];
                [self presentViewController:aler animated:YES completion:^{
                    
                    
                }];
                [self performSelector:@selector(yanshi) withObject:aler afterDelay:1];
                return;
            }
                
            
        }
        [arr addObject:self.hp];

        
        
    }else{
        arr = [NSMutableArray array];
        [arr addObject:self.hp];
        

    }
    [NSKeyedArchiver archiveRootObject:arr toFile:path];
    
    UIAlertController *aler = [UIAlertController alertControllerWithTitle:@"提示" message:@"已收藏" preferredStyle:UIAlertControllerStyleAlert];
    
    [self presentViewController:aler animated:YES completion:^{
        
        
    }];
    [self performSelector:@selector(yanshi) withObject:aler afterDelay:1];
    
    
    
}

//下载方法
-(void)xiazai:(UIButton *)btn
{
    
    DownLoadViewController *down = [[DownLoadViewController alloc]init];
    down.m = self.m;
    [self.navigationController pushViewController:down animated:YES];
    
}


//开始阅读的方法
-(void)kaishi:(UIButton *)btn
{
    
    if (_isM) {
        [self collectionView:self.collection didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
    }else{
        [self collectionView:self.collection didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:self.dataArrOne.count-1 inSection:0]];
    }
    
    
}

-(void)fenxiang:(UIButton *)btn
{
//    
//    [UMSocialConfig setSupportedInterfaceOrientations:UIInterfaceOrientationMaskPortraitUpsideDown];
//    [UMSocialSnsService  presentSnsIconSheetView:self appKey:@"56a7331e67e58ece5500081a" shareText:@"share" shareImage:[UIImage imageNamed:@"00.png"] shareToSnsNames:@[UMShareToSina,UMShareToWechatTimeline,UMShareToTencent,UMShareToWechatSession,UMShareToQQ] delegate:self];

    
    
}
//延迟
-(void)yanshi
{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
